<template>
  <div class="list-container">
    <el-divider>房屋审核</el-divider>
    <vab-query-form>
      <el-form
        ref="form"
        :model="queryForm.queryBean"
        :inline="true"
        @submit.native.prevent
      >
        <el-form-item>
          <el-input
            v-model.trim="queryForm.queryBean.userName"
            placeholder="提交人"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-input
            v-model.trim="queryForm.queryBean.projectName"
            placeholder="项目名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="queryForm.queryBean.reviewStatus"
            placeholder="审核状态"
            clearable
          >
            <el-option label="已通过" :value="2"></el-option>
            <el-option label="未通过" :value="3"></el-option>
            <el-option label="待审核" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            icon="el-icon-search"
            type="primary"
            native-type="submit"
            @click="handleQuery"
          >
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </vab-query-form>
    <el-table
      ref="tableSort"
      v-loading="listLoading"
      :data="list"
      :element-loading-text="elementLoadingText"
      :height="height"
    >
      <el-table-column
        show-overflow-tooltip
        prop="realEstate.estateName"
        label="地产名称"
        width="100"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="realEstate.projectName"
        label="项目名称"
        width="100"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="房屋类型"
        prop="realEstate.estateType"
        width="120"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="realEstate.address"
        label="地址"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="realEstateReview.reviewStatus"
        label="审核状态"
        width="80"
      >
        <template #default="{ row }">
          <el-tag
            size="small"
            :type="
              row.realEstateReview.reviewStatus == 2
                ? 'success'
                : row.realEstateReview.reviewStatus == 3
                ? 'danger'
                : row.realEstateReview.reviewStatus == 1
                ? 'info'
                : 'warning'
            "
          >
            {{ getValue(row.realEstateReview.reviewStatus) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="realEstateReview.reviewTime"
        label="审核时间"
        width="200"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        width="80"
        prop="userInfo.userName"
        label="提交人"
      ></el-table-column>
      <el-table-column show-overflow-tooltip label="操作" width="180px">
        <template #default="{ row }">
          <el-button type="primary" @click="handleEdit(row)">详情</el-button>
          <!-- <el-button type="text" @click="handleEdit(row)">审核</el-button> -->
          <!-- <el-button
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(row)"
          ></el-button> -->
          <!-- <el-button type="text" @click="handleDelete(row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <bind-edit ref="edit"></bind-edit>
    <el-pagination
      :background="background"
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
  </div>
</template>
<script>
  import { getPreviewList } from '@/api/house'
  import { isBlank } from '@/utils/validate'
  import BindEdit from './components/BindEdit'
  import store from '@/store'
  export default {
    name: 'Audit',
    components: {
      BindEdit,
    },
    data() {
      return {
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        background: true,
        elementLoadingText: '正在加载...',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          queryBean: {},
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      this.queryForm.queryBean = {}
      this.fetchData()
    },
    mounted() {},
    methods: {
      getValue(value) {
        switch (value) {
          case 1:
            return '待审核'
          case 2:
            return '已通过'
          case 3:
            return '未通过'
        }
      },
      handleEdit(row) {
        this.$refs['edit'].showEdit(row)
      },
      // handleDelete(row) {
      //   if (row.userInfo.userId) {
      //     this.$baseConfirm('你确定要删除当前项吗', null, async () => {
      //       // const { msg } = await doDelete({ ids: row.id })
      //       this.$baseMessage('尚未做删除功能！', 'warning')
      //       // this.$baseMessage(msg, 'success')
      //       this.fetchData()
      //     })
      //   } else {
      //     this.$baseMessage('删除失败', 'error')
      //     return false
      //   }
      // },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      handleQuery() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getPreviewList(this.queryForm)
        const { body } = data
        const temp = body.data
        this.list = temp
        this.total = body.totalSize
        this.$baseNotify('审核数据获取完毕！', '成功', 'success', 'top-right')
        setTimeout(() => {
          this.listLoading = false
        }, 500)
      },
    },
  }
</script>
